using System;
using System.Collections.Generic;
using System.Text;
using LeisureCenter.Api;
using LeisureCenter.Controls;

namespace LeisureCenter.Core
{
    class MenuManager : IMenuManager
    {
        private Dictionary<string, IMainMenuItemsProvider> providers = new Dictionary<string, IMainMenuItemsProvider>();

        #region IMenuManager Membres

        public void RegisterMainMenuItemsProvider(string name, IMainMenuItemsProvider provider)
        {
            providers.Add(name, provider);
        }

        public void UnRegisterMainMenuItemsProvider(string name)
        {
            providers.Remove(name);
        }

        public void RefreshMainMenu()
        {
            List<IMenuItem> items = new List<IMenuItem>();
            foreach (IMainMenuItemsProvider provider in providers.Values)
            {
                items.AddRange(provider.Items);
            }
            Program.LeisureCenterInstance.MainForm.FillMainMenu(items);
        }

        public void FillSubmenu(IEnumerable<IMenuItem> items)
        {
            Program.LeisureCenterInstance.MainForm.FillSubmenu(items);
        }

        #endregion
    }
}
